<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.images.*" %>
<%@ page import="com.google.appengine.api.blobstore.BlobKey" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>

<!-- Redirect to the login page if there is no session created -->
<%
if (session.getAttribute("username") == null  || session.getAttribute("username") != null ) {
	response.sendRedirect("/login.jsp");
}
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key profilePicKey = KeyFactory.createKey("ProfilePicKey", "mediaFiles");
Query profilePicQuery = new Query("ProfilePic", profilePicKey);
Entity profilePic = datastore.prepare(profilePicQuery).asSingleEntity();
String imageURL = null;
if (profilePic != null) {
	BlobKey blobKey = (BlobKey) profilePic.getProperty("blobKey");
	ImagesService image = ImagesServiceFactory.getImagesService();
	imageURL = image.getServingUrl(blobKey, 300, true);
}
%>

<head>
	<!--CSS-->
	<link rel="stylesheet" href="css/loginStatusBar.css" type="text/css" media="screen"/>
</head>


<div id="loginStatusBarPanel">
	<div style="margin-right:10px; float:left;">
		<% if (imageURL != null) {
			%>
			<img src="<%= imageURL %>" width="48" height="48"/>
			<%
		} else {
			%>
			<img src="images/profile_picture.gif" width="48" height="48"/>
			<%
		}
		%>
	</div>
	<div id="signout">
		<form name="LogOut" method="post" action="/LogOut">
			<a href="/profile.jsp"><%= session.getAttribute("firstName")%> <%= session.getAttribute("lastName")%></a>
			<button type="submit" name="btnSignOut">Sign Out</button>
		</form>
	</div>
</div>